package com.googlecode.i78ba;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.googlecode.i78ba.util.PlatformConfigListener;
import com.googlecode.i78ba.util.StringUtil;
import com.googlecode.i78ba.util.configbean.ModConfig;

@Controller
@RequestMapping(value = "/index")
public class IndexController {
	private static Logger log = LoggerFactory.getLogger(IndexController.class);

	@RequestMapping(value = "")
	public String index(HttpServletRequest request, HttpServletResponse response) {
		String modName = request.getParameter("mod");
		if(StringUtil.isNotEmpty(modName)){
			ModConfig modConfig = PlatformConfigListener.getPlatformConfig().getMods().get(modName);
			if(modConfig != null){
				request.setAttribute("jsp_include", modConfig.getPath());
			}else{
				request.setAttribute("jsp_include", "404.jsp");
			}
		}
		return "index";
	}
}
